import { ITopologyStruct, ModelTheme } from '@app-nextmesh/types';
import { create } from 'zustand';

type State = {
  loaded: boolean; // 是否已加载
  visibleWireframe: boolean;
  info: {
    name: string;
    type: string; // geometry
  };
  topologies: ITopologyStruct[]; // 当前模型拓扑结构信息
};
type Action = {
  setLoaded: (loaded: State['loaded']) => void;
  setVisibleWireframe: (visibleWireframe: State['visibleWireframe']) => void;
  setInfo: (info: State['info']) => void;
  setTopologies: (topologies: State['topologies']) => void;
};

/**
 * 模型数据
 */
export const useModelStore = create<State & Action>((set) => ({
  loaded: false,
  visibleWireframe: true,
  info: { name: '', type: '' },
  topologies: [],
  theme: ModelTheme.Default,
  setLoaded: (loaded: State['loaded']) => set(() => ({ loaded })),
  setVisibleWireframe(visibleWireframe) {
    set(() => ({ visibleWireframe }));
  },
  setInfo: (info: State['info']) => set(() => ({ info })),
  setTopologies: (topologies: State['topologies']) =>
    set(() => ({ topologies })),
}));
